package com.lvwenguo.service.serviceImple;

import com.lvwenguo.dao.BootmDao;
import com.lvwenguo.model.bootmData;
import com.lvwenguo.service.bootmServiceInter;
import com.lvwenguo.utils.JdbcUtil;

import java.sql.Connection;
import java.util.List;

public class bootmServiceImple implements bootmServiceInter {
    private Connection connection;
    private JdbcUtil jdbcUtil;
    private BootmDao bootmDao;
    public bootmServiceImple(){
        connection=JdbcUtil.getJdbcUtil().getConnertion();
        bootmDao=new BootmDao(connection);
    }
    //查询销售，销量前5
    @Override
    public List<bootmData> selectYuJing() {
        String sql="select p.product_name,s.sale_count,s.sale_amount from biz_sale s,biz_product p where p.bar_code=s.product_bar_code ORDER BY s.sale_count DESC LIMIT 5";
        try {
            return bootmDao.selectList(sql,bootmData.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    //查询库存预警低于30
    @Override
    public List<bootmData> selectKuCun() {
        String sql="select pr.bar_code,pr.product_name,s.stock_count from biz_stock s LEFT JOIN biz_product pr on s.product_bar_code=pr.bar_code where s.stock_count<=30";
        try {
            return bootmDao.selectList(sql,bootmData.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
    //保质期预警，当前月，日大小比较
    @Override
    public List<bootmData> selectRiQi() {
        String sql="select pr.bar_code,pr.product_name,pu.exp_date from biz_purchase pu LEFT JOIN biz_product pr on pu.product_id=pr.id where MONTH(exp_date)=MONTH(CURRENT_DATE()) and DAYOFMONTH(exp_date)<DAYOFMONTH(CURRENT_DATE())";
        try {
            return bootmDao.selectList(sql,bootmData.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
